{include file="public/layout" /}
<body>
  <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-body" pad15>
                <div class="layui-form house-table" wid100 lay-filter="">
                  <div class="layui-form-item">
                    <label class="layui-form-label">整站页面</label>
                    <div class="layui-input-block">
                       <button class="layui-btn layui-btn-sm" lay-submit lay-filter="up_site">一键生成</button>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">首页</label>
                    <div class="layui-input-block">
                       <button class="layui-btn layui-btn-sm" lay-submit lay-filter="up_index">一键生成</button>
                    </div>
                  </div>
                  <div class="layui-form-item">
                     <label class="layui-form-label">栏目页</label>
                     <div class="layui-input-block">
                        <select name="html_typeid" id="html_typeid" lay-ignore>
                             <option value="0">所有栏目…</option>
                             {$select_html}
                        </select>
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="up_channel">一键生成</button>
                      </div>
                  </div>
                  <div class="layui-form-item">
                     <label class="layui-form-label">文档页</label>
                     <div class="layui-input-block">
                        <select name="html_arc_typeid" id="html_arc_typeid" lay-ignore>
                             <option value="0">所有文档…</option>
                             {$arc_select_html}
                        </select>
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="up_article">一键生成</button>
                      </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
  </div>

  <script>
  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set'], function(){
    var $ = layui.$
    ,form = layui.form
    ,layer = layui.layer;

    //监听生成整站
    form.on('submit(up_site)', function(data){
        $.ajax({
            url: "{:url('Seo/handle', ['_ajax'=>1])}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('正在处理');
            },
            success: function(res){
                layer.closeAll();
                if (0 == res.code) {
                    showErrorAlert('生成失败！');
                } else {
                    var url = eyou_basefile+"?m=admin&c=Seo&a=site";
                    var index = layer.open({type: 2,title: '开始生成',area: ['500px', '300px'],fix: false, maxmin: false,content: url});
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert('生成失败！');
            }
        });
    })

    //生成首页
    form.on('submit(up_index)', function(data){
        $.ajax({
            url: "{:url('Seo/handle', ['_ajax'=>1])}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('正在处理');
            },
            success: function(res){
                if (0 == res.code) {
                    layer.closeAll();
                    showErrorAlert('生成失败！');
                } else {
                    var timestamp1 = Date.parse(new Date());
                    $.ajax({
                        url:__root_dir__+"/index.php?m=home&c=Buildhtml&a=buildIndex",
                        type:'POST',
                        dataType:'json',
                        data: {_ajax:1},
                        beforeSend:function(){
                            // layer_loading('正在处理');
                            // var index = layer.load(0, {shade: false}); 
                        },
                        success:function(data){
                            if(data.msg !== ""){
                                layer.alert(data.msg, {icon: 5, title:false,closeBtn: 0 },function () {
                                    layer.closeAll();
                                } );
                            }else{
                                layer.closeAll();
                                var timestamp2 = Date.parse(new Date());
                                var timestamp3 = (timestamp2 - timestamp1) / 1000;
                                if (timestamp3 < 1) timestamp3 = 1; 
                                layer.msg("生成完毕，共耗时：<font color='red'>"+timestamp3+"</font> 秒",{icon:1,time:2000}); 
                            }
                        },
                        complete:function(){
                            // layer.alert(1, {icon: 5, title:false});
                        },
                        error: function(e){
                            layer.closeAll();
                            showErrorAlert('生成失败！');
                        }
                    });
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert('生成失败！');
            }
        });
    })
    
    //生成栏目页
    form.on('submit(up_channel)', function(data){
        $.ajax({
            url: "{:url('Seo/handle', ['_ajax'=>1])}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('正在处理');
            },
            success: function(res){
                layer.closeAll();
                if (0 == res.code) {
                    showErrorAlert('生成失败！');
                } else {
                    var typeid = $("#html_typeid").val();     //栏目id
                    var url = eyou_basefile+"?m=admin&c=Seo&a=channel&typeid="+typeid;
                    var index = layer.open({type: 2,title: '开始生成',area: ['500px', '300px'],fix: false, maxmin: false,content: url});
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert('生成失败，请先提交保存配置！');
            }
        });
    })

    //生成文章页
    form.on('submit(up_article)', function(data){
        $.ajax({
            url: "{:url('Seo/handle', ['_ajax'=>1])}",
            type: 'POST',
            dataType: 'json',
            data: data.field,
            beforeSend:function(){
                layer_loading('正在处理');
            },
            success: function(res){
                layer.closeAll();
                if (0 == res.code) {
                    showErrorAlert('生成失败！');
                } else {
                    var typeid = $("#html_arc_typeid").val();     //栏目id
                    var url = eyou_basefile+"?m=admin&c=Seo&a=article&typeid="+typeid;
                    var index = layer.open({type: 2,title: '开始生成',area: ['500px', '300px'],fix: false, maxmin: false,content: url});
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert('生成失败！');
            }
        });
    })

  });
  </script>
{include file="public/footer" /}